package com.xgit.iov.codegen.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xgit.iov.codegen.entity.GenDatasource;
import com.xgit.iov.codegen.mapper.GenDatasourceMapper;
import com.xgit.iov.codegen.service.IGenDatasourceService;
import com.xgit.iov.common.core.service.impl.SuperServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 数据源Service业务层处理
 *
 * @author william
 * @date 2020-02-16
 */

@Service
public class GenDatasourceServiceImpl extends SuperServiceImpl<GenDatasourceMapper, GenDatasource> implements IGenDatasourceService {


    @Autowired
    private GenDatasourceMapper genDatasourceMapper;

    @Override
    public IPage selectList(Page page, GenDatasource genDatasource) {
		return genDatasourceMapper.selectPage(page, new QueryWrapper<GenDatasource>()
			.like(StrUtil.isNotEmpty(genDatasource.getPollName()),"poll_name",genDatasource.getPollName()));
    }

    @Override
    public List<GenDatasource> selectAllList(){
        return genDatasourceMapper.selectList(new QueryWrapper<>());
    }

    /**
     * 新增数据源
     *
     * @param genDatasource 数据源
     * @return 结果
     */
    @Transactional
    @Override
    public int insertGenDatasource(GenDatasource genDatasource) {
        return genDatasourceMapper.insert(genDatasource);
    }

    /**
     * 修改数据源
     *
     * @param genDatasource 数据源
     * @return 结果
     */
    @Transactional
    @Override
    public int updateGenDatasource(GenDatasource genDatasource) {
        return genDatasourceMapper.updateById(genDatasource);
    }

    /**
     * 批量删除数据源
     *
     * @param ids 需要删除的数据源ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteGenDatasourceByIds(Long[] ids) {
        return genDatasourceMapper.deleteBatchIds(CollUtil.toList(ids));
    }

}
